package com.ny.shiyan.shiyan4;

import java.util.Scanner;

public class PaymentSystem {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double amount = 20.0;
        boolean paymentSuccess = false;

        System.out.println("支付系统");
        System.out.println("您需要支付金额: ¥" + amount);
        System.out.println("请选择支付方式:");
        System.out.println("1. 银行卡支付");
        System.out.println("2. 支付宝支付");
        System.out.println("3. 微信支付");

        while (!paymentSuccess) {
            System.out.print("请输入您的选择:");

            if (scanner.hasNextInt()) {
                int choice = scanner.nextInt();
                scanner.nextLine();

                Payment paymentMethod = null;

                switch (choice) {
                    case 1:
                        paymentMethod = new BankCardPayment();
                        break;
                    case 2:
                        paymentMethod = new AlipayPayment();
                        break;
                    case 3:
                        paymentMethod = new WechatPayment();
                        break;
                    default:
                        System.out.println("无效选择，请重新输入!");
                        continue;
                }

                System.out.println("支付处理中");
                paymentSuccess = paymentMethod.pay(amount);

                if (!paymentSuccess) {
                    System.out.println("请尝试其他支付方式:");
                    System.out.println("1. 银行卡支付");
                    System.out.println("2. 支付宝支付");
                    System.out.println("3. 微信支付");
                }
            } else {
                System.out.println("输入错误: 请输入数字选项!");
                scanner.nextLine();
            }
        }

        System.out.println("支付已完成，感谢您的使用!");
        scanner.close();
    }
}
